package com.linq.cool.gateway.config;

import com.linq.cool.gateway.handler.ValidateCodeHandler;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;

/**
 * @Author: yqlin
 * @Date: 2021/1/17 23:37
 * @Description: 路由配置信息
 * 没有controller所以配置路由信息
 * RouterFunction使用RequestPredicate将传入请求映射到HandlerFunction。
 * @Version: 1.0.0
 */
@Configuration
@AllArgsConstructor
public class RouterFunctionConfiguration {

    @Autowired
    private ValidateCodeHandler validateCodeHandler;

    @Bean
    public RouterFunction<?> routerFunction() {
        return RouterFunctions.route(
                // 获取图片验证码路由 /code
                RequestPredicates.GET("/code").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
                validateCodeHandler
        );
    }
}
